<?php

namespace app\admin\controller;

use app\admin\controller\common\Yan_zheng;
use think\Db;
use think\Request;
use think\Validate;

class Sys
{
    #登入页面
    public function index()
    {
        return view('sys');
    }
    public function login()
    {
        return view();
    }

    #验证验证码、账号、密码是否正确
    public function is()
    {
        if(!captcha_check($_POST['validate'])){
            return '验证码错误';
        }



        /*验证特殊字符*/
        $Yan_zheng = new Yan_zheng();
        if(!$error = $Yan_zheng ->is_string([$_POST['account'],$_POST['password']])) {
            return $error;

        }
        //检测用户存在不
        $wh['account'] = ['=',$_POST['account']];
        $wh['password'] = ['=',md5($_POST['password'])];
        $wh['status'] = ['=',1];
        $id = Db::table('bg_admin')
            ->where($wh)
            ->value('id');
        #判断 存在不
        if(is_int($id)){
            $this ->sess($id);
            $Yan_zheng ->rizhi('管理员登入成功');
            return '1';
        }
        else{
            $Yan_zheng ->rizhi('管理员登入失败');
            return '账户或密码错误';
        }

    }

    public function sess($val)
    {
        return session('dsihUGJKJOIJiojf*&%$6uig12@#$sdD',$val);

    }
}
